Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix selection getting lost on Android on the new arch #335

Merged
merged 2 commits into from
Apr 26, 2024

Conversation

j-piasecki
Copy link
Collaborator

@j-piasecki j-piasecki commented Apr 26, 2024

Details

The commit hook is updating the native state of the decorated text input on every shadow tree commit to override the default measurement method. Since the attributed string with the content of the input is also kept in the state, this was causing the state of the native ReactEditText to be updated on every commit, which effectively meant creating a new spannable on every commit and in turn losing the selection spans.

This PR changes the update to also set the event counter to -1 when it doesn't change between updates, which effectively makes the java part of the state updates a no-op in those cases, similarly to how it's done in the core of RN: https://github.com/facebook/react-native/blob/67392cef3c8e036adfd9f77808419221d70f8f18/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputShadowNode.cpp#L155-L163

(-1 instead of 0, like above, because 0 would be the most recent counter during the first render)

Always setting the event counter to -1 also seemed to work fine but after quite a while of figuring out issues due to lost state updates in commit hooks, I'm not sure if we want to go that far now. It's something we may want to investigate in the future though.

Before After
Screen.Recording.2024-04-26.at.16.43.06.mov
Screen.Recording.2024-04-26.at.15.34.11.mov

Manual Tests

This is testable in the example app, simply select some text. The handles should appear and be draggable. The text editing part should also work correctly.

@j-piasecki j-piasecki requested review from tomekzaw and Skalakid April 26, 2024 14:22
@j-piasecki j-piasecki merged commit 5404e93 into main Apr 26, 2024
5 checks passed
@j-piasecki j-piasecki deleted the @jpiasecki/fix-selection-android branch April 26, 2024 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants